package cn.gyxy.controller;

import cn.gyxy.Aspect.Bsrizhi;
import cn.gyxy.pojo.Zhigong;
import cn.gyxy.service.ZhigongService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
@RequestMapping("/lgbs")
public class ZhigongController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private ZhigongService zhigongService;

    //首页
    @RequestMapping({"/homepage/{name}","/homepage"})
    public String homepage(Model model, @PathVariable(required = false) String name) throws UnsupportedEncodingException {
//        String value = request.getParameter("name");
//
//        value = new String(value.getBytes("iso-8859-1"),"utf-8");
        List<Zhigong> zhigonglist =zhigongService.selectZhiGong(name);
 model.addAttribute("zhigonglist",zhigonglist);
        return "shouye";

    }
    @RequestMapping({"/chaxunzhigong{name}","/chaxunzhigong"})
    public  String chaxun(Model model, @PathVariable(required = false) String name) throws UnsupportedEncodingException {
//        String value = request.getParameter("name");
//
//        value = new String(value.getBytes("iso-8859-1"),"utf-8");
        List<Zhigong> zhigonglist =zhigongService.selectZhiGong(name);
        model.addAttribute("zhigonglist",zhigonglist);
        return "zhigongChaxun";
    }




    @RequestMapping("/xiangqing/{id}")
    public  String  xiangqing(Model model,@PathVariable Integer id) {
        Zhigong zhigong = zhigongService.selectId(id);
        model.addAttribute("zhigong", zhigong);
        return "zhigong-update";
        //http://localhost/brand/doFindBrands/${name}
    }
    @RequestMapping("/doUpdateZhiGong")
public  String zhigongUpdate(Zhigong zhigong){
        zhigongService.zhiGongupdate(zhigong);
        return  "fanhui";
}
//    @RequiresPermissions("1")
@RequestMapping("/doDeleteById/{id}")
public  String  doDeleteById(@PathVariable Integer id){
  int row= zhigongService.doDeleteById(id);
 return "redirect:/lgbs/homepage";
}



@RequestMapping("/zhigomhAddUI")
public  String  zhigomhAddUI(){

        return "zhigong-Add";
}

@RequestMapping("/zhigomhAdd")
public String zhigomhAdd( Zhigong zhigong){
zhigongService.zhigomhAdd(zhigong);
        return "redirect:/lgbs/homepage";
}

@RequestMapping("/test/{name}")
public String test(){
        return "成功";
}
    }

